<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="text" id="i2">
<input type="button" value="加" onclick="fn(1)">
<input type="button" value="减" onclick="fn(2)">
<input type="button" value="乘" onclick="fn(3)">
<input type="button" value="除" onclick="fn(4)">
<div></div>
<script>
    function fn(x) {
    let i = document.querySelector("#i1");
    let d = document.querySelector("#i2");
    let c = document.querySelector("div");
    if (isNaN(i.value) || isNaN(d.value)) {
        c.innerText = "重输!";
        return;
    }
        switch (x) {
            case 1:
                c.innerText = i.value * 1 + d.value * 1;
                break;
            case 2:
                c.innerText = i.value - d.value;
                break;
            case 3:
                c.innerText = i.value * d.value;
                break;
            case 4:
                c.innerText = i.value / d.value;
                break;
        }

    }
</script>
</body>
</html>